/*
 * 标签
 */

import { createAPI } from '@/utils/request'
import moment from 'moment'

// 标签列表

export const list = params => createAPI('/tags', 'get', params).then(res => {
  const data = {
    ...res.data,
    items: res.data.items.map((row, idx) => {
      return {
        ...row,
        index: (params.page - 1) * params.pagesize + idx + 1,
        addDate: moment(row.addDate).format('YYYY-MM-DD'),
        state: row.state === 1 ? '已启用' : '已禁用'
      }
    })
  }
  return data
})

// 标签简单列表
export const simple = data => createAPI('/tags/simple', 'get', data)

// 标签详情
export const detail = data => createAPI(`/tags/${data.id}`, 'get', data)

// 标签添加
export const add = data => createAPI('/tags', 'post', data)

// 标签修改
export const update = data => createAPI(`/tags/${data.id}`, 'put', data)

// 标签删除
export const remove = data => createAPI(`/tags/${data.id}`, 'delete', data)

// 标签状态
export const changeState = data => createAPI(`/tags/${data.id}/${data.state}`, 'post', data)
